package com.yidu.t299.dao.cfj;

import com.yidu.t299.domain.cfj.ChangeAnnal;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ChangeAnnalMapper {
    /**
     * 根据编号删除信息
     * @param annalId 编号
     * @return 影响的行数(返回1则为成功)
     */
    @Delete({
            "delete from change_annal" +
                    " where annal_id = #{annal_id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer annalId);

    /**
     * 添加信息
     * @param changeAnnal
     * @return 影响的行数(返回1则为成功)
     */
    @Insert({
            "insert into change_annal (annal_id,record_id,annal_body,annal_date)" +
                    " values (#{annalId,jdbcType=INTEGER},#{recordId,jdbcType=INTEGER}," +
                    "#{annalBody,jdbcType=VARCHAR},#{annalDate,jdbcType=VARCHAR})"
    })
    int insert(ChangeAnnal changeAnnal);

    /**
     * 根据编号查询指定的信息
     * @param annalId
     * @return
     */
//    SELECT annal_id,c.record_id,r.record_name,annal_body,annal_date FROM change_annal c
//    JOIN record r ON r.record_id = c.record_id
    @Select({
            "select annal_id,c.record_id,r.record_name,annal_body,annal_date from change_annal c" +
                    "join record r on r.record_id = c.record_id" +
                    " where annal_id = #{annalId,jdbcType=INTEGER}"
    })
    @Results(id = "ChangeAnnalMap",value = {
            @Result(id = true,column = "annal_id",property = "annalId"),
            @Result(column = "record_id",property = "recordId"),
            @Result(column = "record_name",property = "recordName"),
            @Result(column = "annal_body",property = "annalBody"),
            @Result(column = "annal_date",property = "annalDate")
    })
    ChangeAnnal selectByPrimaryKey(Integer annalId);

    /**
     * 按条件分页查询校区数据集合
     * @param rows 每页的行数
     * @param page 页码
     * @param condition 条件参数
     * @return 对象集合
     */
    @Select("select * from (select annal_id,change_annal.record_id,record.record_name,annal_body,annal_date from change_annal " +
            "             join record  on record.record_id = change_annal.record_id) p   where 1=1 ${condition} limit #{page},#{rows}")
    @ResultMap("ChangeAnnalMap")
    List<ChangeAnnal> selectByPage(@Param("rows") int rows, @Param("page") int page, @Param("condition") String condition);

    /**
     * 按条件查询表中数据行数
     * @param condition 条件参数
     * @return 数据行数
     */
    @Select("select count(*) from (select annal_id,c.record_id,r.record_name,annal_body,annal_date from change_annal c " +
            "join record r on r.record_id = c.record_id ) p  where 1=1 ${condition}")
    int selectCount(@Param("condition") String condition);

    /**
     * 根据信息修改其数据
     * @param changeAnnal
     * @return 影响的行数(返回1则为成功)
     */
    @Update({
            "update change_annal" +
            " set record_id = #{recordId,jdbcType=INTEGER},",
            " annal_body = #{annalBody,jdbcType=VARCHAR}," +
            " annal_date = #{annalDate,jdbcType=VARCHAR}" +
            " where annal_id = #{annalId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(ChangeAnnal changeAnnal);
}